import request from '@/utils/request'
import { ApiModulesRoutes } from '@/consts'

/**
 * 获取物模型详情
 * @param {String} metadataId
 */

export function getModelDetail(metadataId) {
  return request({
    url: `${ApiModulesRoutes.IOT}/metadata/findMetadataById`,
    method: 'GET',
    params: { metadataId },
  })
}

/**
 * 修改物模型
 * @param {String} data.id
 * @param {String} data.name
 * @param {String} data.remark
 */
export function updateMetadata(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/metadata/updateMetadata`,
    method: 'POST',
    data,
  })
}

/**
 * 查询物模型服务列表
 * @param {String} data.metadataId
 * @param {String} data.pageNo
 * @param {String} data.pageSize
 */
export function findServiceList(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/Services/findServicesPageByParam`,
    method: 'POST',
    data,
  })
}

/**
 * 新增服务
 * @param {String} data.identifier
 * @param {String} data.name
 * @param {String} data.metadataId
 * @param {String} data.remark
 */

export function addServe(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/Services/addServices`,
    method: 'POST',
    data,
  })
}

/**
 * 删除指定服务
 * @param {String} serveId
 */

export function delServicesById(serveId) {
  return request({
    url: `${ApiModulesRoutes.IOT}/Services/delServicesById`,
    method: 'GET',
    params: { serveId },
  })
}

/**
 * 修改服务
 * @param {String} data.id
 * @param {String} data.identifier
 * @param {String} data.name
 * @param {String} data.metadataId
 * @param {String} data.remark
 */

export function updateServe(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/Services/updateServices`,
    method: 'POST',
    data,
  })
}

/**
 * 查询物模型属性列表
 * @param {String} data.metadataId
 * @param {String} data.pageNo
 * @param {String} data.pageSize
 */
export function findPropertyList(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/property/findPropertyPageByParam`,
    method: 'POST',
    data,
  })
}

/**
 * 新增属性
 * @param {String} data.name
 * @param {String} data.type
 * @param {String} data.property
 * @param {String} data.metadataId
 * @param {String} data.remark
 */

export function addField(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/property/addProperty`,
    method: 'POST',
    data,
  })
}

/**
 * 删除指定属性
 * @param {String} fieldId
 */

export function delPropertyById(fieldId) {
  return request({
    url: `${ApiModulesRoutes.IOT}/property/delPropertyById`,
    method: 'GET',
    params: { fieldId },
  })
}
/**
 * 修改属性
 * @param {String} data.id
 * @param {String} data.name
 * @param {String} data.type
 * @param {String} data.property
 * @param {String} data.metadataId
 * @param {String} data.remark
 */

export function updateProperty(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/property/updateProperty`,
    method: 'POST',
    data,
  })
}


/**
 * 查询物模型事件列表
 * @param {String} data.metadataId
 * @param {String} data.pageNo
 * @param {String} data.pageSize
 */
export function findIotEventPageByParam(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/event/findIotEventPageByParam`,
    method: 'POST',
    data,
  })
}

/**
 * 新增事件
 * @param {String} data.name
 * @param {String} data.identifier
 * @param {String} data.eventTypeEnum
 * @param {String} data.metadataId
 * @param {String} data.remark
 */

export function addEvent(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/event/addIotEvent`,
    method: 'POST',
    data,
  })
}

/**
 * 删除指定事件
 * @param {String} iotEventId
 */

export function delEvent(iotEventId) {
  return request({
    url: `${ApiModulesRoutes.IOT}/event/delIotEventById`,
    method: 'GET',
    params: { iotEventId },
  })
}
/**
 * 修改事件
 * @param {String} data.name
 * @param {String} data.identifier
 * @param {String} data.eventTypeEnum
 * @param {String} data.metadataId
 * @param {String} data.remark
 */

export function updateEvent(data) {
  return request({
    url: `${ApiModulesRoutes.IOT}/event/updateIotEvent`,
    method: 'POST',
    data,
  })
}
